#!/usr/bin/python3

from telnetlib import Telnet

def routerclearline(username, password, rackno, routerno = 20):
    if rackno == 'BJRack01':
		rackip = '172.17.100.111'
	elif rackno == 'BJRack02':
		rackip = '172.17.100.112'
	elif rackno == 'BJRack3':
		rackip = '172.17.100.113'

	tn = Telnet(rackip)

	sendusername = username.encode()
	tn.read_until(b'Username: ')
	tn.write(sendusername + b'\n')

	sendpassword = password.encode()
	tn.read_until(b'Password: ')
	tn.write(sendpassword + b'\n')

	tn.read_until(b'QYT-Rack')

	if routerno == 20:
		for i in range(20):
			command = 'clear line ' + str(i) +'\n\n'
			tn.write(command.encode())
	else:
		command = 'clear line ' + str(routerno) +'\n\n'
		tn.write(command.encode())

	tn.write(b'exit\n')
	print(tn.read_all().decode('ascii'))


if __name__ == "__main__":
	routerclearline('labtest', 'xxxxx', 'BJRack01', 1)
